var express = require('express');
var router = express.Router();
var Upload = require('./../sql/upload');
var sql = require('./../sql');
var utils = require('./../utils')
var uuid = require('node-uuid');
var bcrypt = require('bcryptjs');
var jwt = require('jsonwebtoken');
var salt = bcrypt.genSaltSync(10); // 加密级别
var  checkCode = require('./checkCode.js')
var User = require('./../sql/user');
const multer = require('multer')

const upload = multer({ dest: __dirname + '/../uploads' })
  router.post('/',upload.single('file'), async (req, res) => {
      const file = req.file
      let userid = req.body.userid
    //本身req是没有file的通过中间件multer给req挂载上去的
    file.url = `http://localhost:3000/uploads/${file.filename}`
    sql.update(User,{userid},{$set:{avatar:file.url}})
      res.send(file)
  })




module.exports = router
